package com.lin.controller;

import com.lin.common.error.CustomRuntimeException;
import com.lin.common.rest.ResMsg;
import com.lin.controller.req.AddQuestionsReqMsg;
import com.lin.controller.req.ChatListReqMsg;
import com.lin.controller.req.QuestionsReqMsg;
import com.lin.controller.res.CustomerChatPageResMsg;
import com.lin.controller.res.QuestionsPageResMsg;
import com.lin.service.qanda.QuestionsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;

@Api(tags = "问题入口")
@RestController
@RequestMapping("/msvc")
public class QuestionsController {

    @Autowired
    private QuestionsService questionsService;

    @ApiOperation("问题列表")
    @PostMapping("/questions")
    public ResMsg<QuestionsPageResMsg> questions(@Valid @RequestBody QuestionsReqMsg reqMsg) {
        ResMsg<QuestionsPageResMsg> urs = new ResMsg<>();
        return urs.withData(questionsService.list(reqMsg.getCustomerId(), reqMsg.getPageSize(), reqMsg.getPageNo()));
    }

    @ApiOperation("新增更新问题")
    @PostMapping("/questions/save")
    public ResMsg<Integer> save(@Valid @RequestBody AddQuestionsReqMsg reqMsg) throws IOException, CustomRuntimeException {
        ResMsg<Integer> urs = new ResMsg<>();
        return urs.withData(questionsService.save(reqMsg));
    }

}
